<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="所属订单号" prop="orderId">
        <el-input v-model="queryParams.orderId" placeholder="所属订单号" clearable style="width: 240px;" size="mini"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="商品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="商品名称" clearable style="width: 100px;" size="mini"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="打分等级" prop="star">
        <el-select v-model="queryParams.star" placeholder="打分等级" clearable size="mini">
          <el-option v-for="dict in levelOptions" :key="dict.value" :label="dict.label" :value="+dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" size="mini" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange" :height="tableHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column type="expand">
        <template slot-scope="{row}">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="评论内容:">
              <span>{{ row.content }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="客户头像" align="center" prop="memberAvatar" width="100px">
        <template slot-scope="{row}">
          <span v-if="row.memberAvatar==''">暂无</span>
          <el-image v-else :src="row.memberAvatar" style="width: 40px; height: 40px" fit="fill"
                    :preview-src-list="[row.memberAvatar]"/>
        </template>
      </el-table-column>
      <el-table-column label="客户昵称" align="center" prop="memberNickname"/>
      <el-table-column label="所属订单号" align="center" prop="orderId"/>
      <el-table-column label="商品名称" align="center" prop="productName"/>
      <el-table-column label="打分" align="center" prop="star" :formatter="levelFormat"/>
      <el-table-column label="创建时间" align="center" prop="gmtCreate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gmtCreate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
                @pagination="getList"/>
  </div>
</template>

<script>

import { listOrderEvaluation } from '@a/beauty/orderEvaluation'

export default {
  name: 'orderEvalutaion',
  data() {
    return {
      tableHeight: window.innerHeight - 340,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 状态数据字典
      statusOptions: [],
      // 退费类型数据字典
      backTypeOptions: [],
      // 退费订单类型
      typeOptions: [],
      // 日期范围
      dateRange: [],
      // 打分等级
      levelOptions: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        parentId: undefined,
        productName: undefined,
        orderId: undefined,
        star: undefined
      }
    }
  },
  created() {
    this.getList()
    this.getDictItems('beauty_product_star_level').then(response => {
      this.levelOptions = response.data
    })
  },
  methods: {
    levelFormat(row, column) {
      return this.selectDictLabel(this.levelOptions, row.star)
    },
    /** 查询列表 */
    getList() {
      this.loading = true
      listOrderEvaluation(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.list = response.data.records
          this.total = response.data.total
          this.loading = false
        }
      )
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    }
  }
}
</script>
<style scoped lang="scss">
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>

